from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-20 14:06:09.493405
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 20, Mar, 2021
Time: 14:06:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.0001
Nobs: 236.000 HQIC: -47.7886
Log likelihood: 2778.06 FPE: 1.03422e-21
AIC: -48.3211 Det(Omega_mle): 7.11878e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.465101 0.131747 3.530 0.000
L1.Burgenland 0.067706 0.066575 1.017 0.309
L1.Kärnten -0.207517 0.056374 -3.681 0.000
L1.Niederösterreich 0.146704 0.148941 0.985 0.325
L1.Oberösterreich 0.255465 0.134568 1.898 0.058
L1.Salzburg 0.211098 0.072051 2.930 0.003
L1.Steiermark 0.102981 0.096023 1.072 0.284
L1.Tirol 0.108774 0.064576 1.684 0.092
L1.Vorarlberg -0.001388 0.059397 -0.023 0.981
L1.Wien -0.134687 0.123054 -1.095 0.274
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.470419 0.156005 3.015 0.003
L1.Burgenland 0.019632 0.078833 0.249 0.803
L1.Kärnten 0.347962 0.066755 5.213 0.000
L1.Niederösterreich 0.089815 0.176366 0.509 0.611
L1.Oberösterreich -0.104215 0.159347 -0.654 0.513
L1.Salzburg 0.188240 0.085317 2.206 0.027
L1.Steiermark 0.190737 0.113704 1.677 0.093
L1.Tirol 0.133833 0.076467 1.750 0.080
L1.Vorarlberg 0.157523 0.070334 2.240 0.025
L1.Wien -0.481179 0.145712 -3.302 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.308679 0.061276 5.037 0.000
L1.Burgenland 0.092461 0.030965 2.986 0.003
L1.Kärnten -0.019801 0.026220 -0.755 0.450
L1.Niederösterreich 0.065113 0.069274 0.940 0.347
L1.Oberösterreich 0.298637 0.062589 4.771 0.000
L1.Salzburg 0.013389 0.033511 0.400 0.689
L1.Steiermark -0.009828 0.044661 -0.220 0.826
L1.Tirol 0.071195 0.030035 2.370 0.018
L1.Vorarlberg 0.101519 0.027626 3.675 0.000
L1.Wien 0.085161 0.057233 1.488 0.137
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.219321 0.065508 3.348 0.001
L1.Burgenland 0.000038 0.033103 0.001 0.999
L1.Kärnten 0.014665 0.028031 0.523 0.601
L1.Niederösterreich 0.032212 0.074057 0.435 0.664
L1.Oberösterreich 0.398033 0.066911 5.949 0.000
L1.Salzburg 0.081949 0.035825 2.287 0.022
L1.Steiermark 0.173939 0.047745 3.643 0.000
L1.Tirol 0.042603 0.032109 1.327 0.185
L1.Vorarlberg 0.080327 0.029534 2.720 0.007
L1.Wien -0.042986 0.061185 -0.703 0.482
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.515195 0.129109 3.990 0.000
L1.Burgenland 0.064109 0.065242 0.983 0.326
L1.Kärnten 0.004305 0.055245 0.078 0.938
L1.Niederösterreich -0.030656 0.145958 -0.210 0.834
L1.Oberösterreich 0.147400 0.131874 1.118 0.264
L1.Salzburg 0.069792 0.070608 0.988 0.323
L1.Steiermark 0.095203 0.094100 1.012 0.312
L1.Tirol 0.221837 0.063283 3.505 0.000
L1.Vorarlberg 0.027977 0.058208 0.481 0.631
L1.Wien -0.104438 0.120590 -0.866 0.386
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185675 0.095396 1.946 0.052
L1.Burgenland -0.020683 0.048206 -0.429 0.668
L1.Kärnten -0.013721 0.040820 -0.336 0.737
L1.Niederösterreich 0.005406 0.107846 0.050 0.960
L1.Oberösterreich 0.413012 0.097439 4.239 0.000
L1.Salzburg 0.007479 0.052171 0.143 0.886
L1.Steiermark -0.018108 0.069529 -0.260 0.795
L1.Tirol 0.169996 0.046759 3.636 0.000
L1.Vorarlberg 0.050369 0.043009 1.171 0.242
L1.Wien 0.226600 0.089101 2.543 0.011
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.249208 0.123215 2.023 0.043
L1.Burgenland 0.025673 0.062264 0.412 0.680
L1.Kärnten -0.051452 0.052724 -0.976 0.329
L1.Niederösterreich -0.044759 0.139296 -0.321 0.748
L1.Oberösterreich -0.039674 0.125854 -0.315 0.753
L1.Salzburg 0.077835 0.067385 1.155 0.248
L1.Steiermark 0.362114 0.089805 4.032 0.000
L1.Tirol 0.456088 0.060395 7.552 0.000
L1.Vorarlberg 0.156813 0.055551 2.823 0.005
L1.Wien -0.186556 0.115085 -1.621 0.105
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126579 0.144655 0.875 0.382
L1.Burgenland 0.030429 0.073098 0.416 0.677
L1.Kärnten -0.059886 0.061898 -0.967 0.333
L1.Niederösterreich 0.207597 0.163534 1.269 0.204
L1.Oberösterreich -0.026714 0.147754 -0.181 0.857
L1.Salzburg 0.246539 0.079110 3.116 0.002
L1.Steiermark 0.137264 0.105431 1.302 0.193
L1.Tirol 0.041841 0.070904 0.590 0.555
L1.Vorarlberg 0.073826 0.065217 1.132 0.258
L1.Wien 0.223509 0.135111 1.654 0.098
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.579865 0.078658 7.372 0.000
L1.Burgenland -0.034067 0.039748 -0.857 0.391
L1.Kärnten -0.018836 0.033658 -0.560 0.576
L1.Niederösterreich 0.014701 0.088924 0.165 0.869
L1.Oberösterreich 0.316197 0.080343 3.936 0.000
L1.Salzburg 0.013164 0.043017 0.306 0.760
L1.Steiermark -0.016617 0.057329 -0.290 0.772
L1.Tirol 0.083465 0.038555 2.165 0.030
L1.Vorarlberg 0.113589 0.035463 3.203 0.001
L1.Wien -0.043057 0.073468 -0.586 0.558
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.132567 0.047312 0.182078 0.236144 0.062586 0.134226 -0.028600 0.161528
Kärnten 0.132567 1.000000 0.004926 0.196151 0.167328 -0.103262 0.142990 0.017251 0.305092
Niederösterreich 0.047312 0.004926 1.000000 0.263971 0.060201 0.265429 0.155775 0.050258 0.313656
Oberösterreich 0.182078 0.196151 0.263971 1.000000 0.290171 0.264518 0.087025 0.070282 0.139436
Salzburg 0.236144 0.167328 0.060201 0.290171 1.000000 0.117974 0.065511 0.087054 -0.002590
Steiermark 0.062586 -0.103262 0.265429 0.264518 0.117974 1.000000 0.117536 0.117994 -0.121942
Tirol 0.134226 0.142990 0.155775 0.087025 0.065511 0.117536 1.000000 0.165580 0.150772
Vorarlberg -0.028600 0.017251 0.050258 0.070282 0.087054 0.117994 0.165580 1.000000 0.020430
Wien 0.161528 0.305092 0.313656 0.139436 -0.002590 -0.121942 0.150772 0.020430 1.000000